package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"iot-base/devc/common/loader"
)

type status struct {
	devid        string
	RegistryCode string //用于存储发送到控制器下发的注册码
	Session      string //用于存储当前建立的sessionID
}

type order int

const (
	sendCard   order = 1
	queryCard  order = 2
	deleteCard order = 3
	openDoor   order = 4
	closeDoor  order = 5
)

type sc struct {
	step1 bool
	step2 bool
	step3 bool
}

type dc struct {
	step1 bool
	step2 bool
}

//此协议只适用于门禁通过人脸系统进行开门操作

var Registtable map[string]status //key值存储设备SN值
var Order order

var card int
var sc1 sc
var dc1 dc
var queryres chan string

func main() {
	r := gin.Default()
	api := r.Group("/iclock")
	api.GET("/push", push)            //获取配置参数
	api.GET("/cdata", newEdge)        //注册新的设备
	api.POST("/cdata", Edge)          //设置属性id
	api.GET("/ping", ping)            //处理心跳
	api.POST("/registry", regist)     //返回注册的设备
	api.GET("/getrequest", request)   //处理请求下发命令
	api.POST("/devicecmd", cmdreq)    //返回命令处理结果
	api.POST("/querydata", querydata) //返回查询结果

	//http.HandleFunc("/iclock/push", push)
	//http.HandleFunc("/iclock/cdata", sayhello)
	//http.HandleFunc("/iclock/registry", regist)
	//http.HandleFunc("/iclock/ping", ping)
	//http.HandleFunc("/iclock/getrequest", request)
	//http.HandleFunc("/iclock/devicecmd", cmdreq)
	//http.HandleFunc("/iclock/querydata", querydata)

	loader.SetParam(false, "guard", 30, nil)
	go registserve()
	//err := http.ListenAndServe(":8088", nil) //设置监听的端口
	//if err != nil {
	//	log.Fatal("ListenAndServe: ", err)
	//}
	err := r.Run(":8088")
	if err != nil {
		fmt.Println("run err:", err)
	}
}

func ping(c *gin.Context) {
	c.Writer.Write([]byte("OK"))
}
